-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add a phase to Dotty that hides Dotty bottom types from JVM. #1002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
/rebuild |
@odersky please review. |
@@ -263,6 +263,12 @@ object Erasure extends TypeTestsCasts{ | |||
else | |||
cast(tree, pt) | |||
} | |||
|
|||
|
|||
/** Is `tpe` a type which is a bottom type for Dotty, but not a bottom type for JVM */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no bottom type on the JVM so I don't really understand the naming of this function, how is it different from Definitions#isBottomType
?
|
/** Is `tpe` a type which is a bottom type for Dotty, but not a bottom type for JVM */ | ||
def isNonJVMBottomType(tpe: Type)(implicit ctx: Context): Boolean = { | ||
tpe.derivesFrom(ctx.definitions.NothingClass) || tpe.derivesFrom(ctx.definitions.NullClass) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, why not use Definitions#isBottomType?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitions#isBottomType(tp) is defined to be tp.symbol \in {NothingClass, NullClass}
It does not work for types that do not return a usable symbol, such as And\Or types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I update Definitions#isBottomType to account for Null | Nothing
and Int & Nothing
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think it's OK to leave the two separate. Maybe rename the second to
derivesFromBottomType
to make clear that refinements and & / | count as well?
On Fri, Dec 18, 2015 at 6:32 PM, Dmitry Petrashko [email protected]
wrote:
In src/dotty/tools/dotc/transform/Erasure.scala
#1002 (comment):@@ -263,6 +263,12 @@ object Erasure extends TypeTestsCasts{
else
cast(tree, pt)
}
+
+
- /** Is
tpe
a type which is a bottom type for Dotty, but not a bottom type for JVM */- def isNonJVMBottomType(tpe: Type)(implicit ctx: Context): Boolean = {
tpe.derivesFrom(ctx.definitions.NothingClass) || tpe.derivesFrom(ctx.definitions.NullClass)
- }
}Should I update Definitions#isBottomType to account for Null | Nothing
and Int & Nothing?—
Reply to this email directly or view it on GitHub
https://github.com/lampepfl/dotty/pull/1002/files#r48048942.
Martin Odersky
EPFL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
I do not have a strong opinion on this either. So I've implemented class A {
val s: Nothing = null.asInstanceOf[Nothing]
} scalac emmits: public class A {
private final Nothing. s = null;
public Nothing. s() {
return this.s;
}
} PS: the |
Being compatible with scalac seems OK here, but note that the following fails at runtime in object X {
def main(args: Array[String]): Unit = {
val x: Int = null.asInstanceOf[Nothing]
}
} |
And now that I think about it, this might be a good think because in the following: object X {
def main(args: Array[String]): Unit = {
val x: Int = null.asInstanceOf
}
} The type parameter of |
/** Is `tpe` a type which is a bottom type for Dotty, but not a bottom type for JVM */ | ||
def isNonJVMBottomType(tpe: Type)(implicit ctx: Context): Boolean = { | ||
tpe.derivesFrom(ctx.definitions.NothingClass) || tpe.derivesFrom(ctx.definitions.NullClass) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now did a similar change in definitions (f780a37).
So it's best if you cherry-pick the commit and use defn.isBottomType.
It is very convenient to have bottom types in type system. Unfortunately JVM does not have bottom types and we need to insert casts that would make bytecode pass verification.
45278e1
to
64e17d0
Compare
I've addressed most comments except the |
FTR, in Scala.js we recently decided to go against what scalac/JVM does for |
The following comments have not been addressed: |
/rebuild |
Let's either rebase and try again or close. |
It is very convenient to have bottom types in type system. Unfortunately
JVM does not have bottom types and we need to insert casts that would make
bytecode pass verification.